home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / cap / README < prev    next >
Text File  |  1996-11-11  |  4KB  |  81 lines

  1.  
  2.              ~4Dgifts/toolbox/src/exampleCode/opengl/cap README
  3.  
  4.  
  5.                      Open GL Interference Checking
  6.                      =============================
  7.  
  8.       Capping is a trick employed so that we can use hollow models
  9.       to portray solids, and is used in applications where objects
  10.       could be clipped (such as CAD).  Interference checking is
  11.       a method of showing the regions of intersection between two
  12.       separate objects.
  13.  
  14.       The program allows the user to toggle capping on and off.  Note 
  15.       that there is a performance hit you take with capping on.  The
  16.       reasons for this are outlined below when I discuss the algorithm.
  17.  
  18.       This open gl example is based on Kurt Akeley's 'cap' program.
  19.       It is by no means as robust in a demonstrational sense, meaning
  20.       it does not read object in from a file, nor can one move around the
  21.       clipping planes or the viewpoint.
  22.  
  23.       What it does do is to apply a clipping plane in the XY plane at z=0,
  24.       and bring up two torii.  The clipped torii are capped using the same
  25.       material as the rest of each respective surface.  The interference
  26.       between the two objects is shown in red.  The yellow square is an
  27.       outline of a plane coinciding to the arbitrary clipping plane 0.
  28.       The axes are drawn at the origin to indicate the orientation of the
  29.       clipping plane.
  30.  
  31.       The capping and interference checking are both done using the
  32.       stencil buffer.  
  33.  
  34.       The capping is done by rendering each object in the scene twice.
  35.       The first time, the objects are each drawn with backfacing on
  36.       (since the capping will prevent the user from seeing the inner
  37.       portions of the clipped objects).  Then we disable writes to the
  38.       color and depth buffers.  We'll use the low order bit of the stencil
  39.       buffer to determine where we've drawn part of the object.  Then
  40.       we'll draw the object again, using the stencil buffer to keep
  41.       track of which pixels we've tried to draw something to.  Where the
  42.       value in the stencil buffer is odd, the inside of the solid was
  43.       (rather would have been) visible.
  44.  
  45.       After the object is rendered for the second time, we draw the clipping
  46.       plane, using the same material property as the object's.  In order
  47.       to make sure that the cap is drawn correctly, we do two things.  First,
  48.       we shut off the clipping plane (otherwise the cap itself could be
  49.       clipped).  Then, we transform the origin to the location of the clipping
  50.       plane.  This prevents any problems related to viewer position from
  51.       occuring.  For example, if the origin of the model view matrix were
  52.       not where we expected, the cap might be drawn at an offset to its
  53.       expected position.
  54.  
  55.       The interference checking is done after all of the objects in the scene
  56.       are drawn with their caps.  Since the values in the stencil buffer
  57.       are still intact, we draw a large rectangle stenciling those regions
  58.       with pixel access counts of two or greater.  In this example, we
  59.       draw a red rectangle, ergo the name "little red cap".
  60.  
  61.       Objects can be animated to ensure the capping and interference
  62.       checking is done in real time.
  63.  
  64.       To change the objects, their properties, or transforms, edit the
  65.       shapes data structure in ogl_interfere.c.  This data structure will 
  66.       also take a uniform scaling factor if you wish to grow or shrink 
  67.       each shape.
  68.  
  69.       At this writing there is a known bug in hardware-supported stencil
  70.       buffers that cause the all shapes (except the first) to be capped
  71.       in their entirety, not just in the clipped areas.  I have observed
  72.       this on Extreme, Elan, and Reality Engine graphics and there is
  73.       a bug filed against it.  Hopefully by the time anyone reads this,
  74.       it will have been fixed.  You can see the working version on 
  75.       machines with XL (newport) or starter graphics (since stencilling is
  76.       software-supported).
  77.  
  78.       Paul C. David
  79.       pcd@sgi.com
  80.       1/94
  81.